﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace xab
{


    [Serializable]
    public class AssetInfo
    {
        /// <summary>
        /// lua文件资源会用\作为特殊字符标识相对路径
        /// </summary>
        public string assetPath;

        /// <summary>
        /// 所属Bundle, 反序列化时会创建空对象
        /// </summary>
        public BundleName ownBundle;

        /// <summary>
        /// 被哪些Bundle引用了
        /// </summary>
        public List<BundleName> usedByBundles = new List<BundleName>();

        public AssetInfo(string asset)
        {
            this.assetPath = asset;
        }

        public void SetOwnBundle(BundleName bn)
        {
            if (null != ownBundle && ownBundle != bn)
            {
                Debug.LogError($"规则存在重叠, 一个文件被设置了多次Bundle名: {assetPath}, old: {ownBundle.displayName}, new: {bn.displayName}");
                return;
            }

            //Debug.Log($"SetOwnBundle: asset:{asset}, bundle:{bn.displayName}");
            ownBundle = bn;
        }

        public void AddUsedByBundle(BundleName bn)
        {
            if (!usedByBundles.Contains(bn))
                usedByBundles.Add(bn);
        }

    }


}
